package com.ars.common.dao;

import com.ars.common.beans.Active.Mysubmit;
import com.ars.common.utils.DBUtil;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.TreeMap;

public class FindMySubmit {
    public TreeMap<Integer, Mysubmit> findsub(String UserID) throws SQLException {
        TreeMap<Integer, Mysubmit> tmp = new TreeMap<Integer, Mysubmit>();

        System.out.println("findsubTest");

        String sql = "SELECT m.submitTime ,m.material, a.id ,a.`name`\n"  +
                "FROM material m\n" +
                "LEFT JOIN active a ON m.id = a.id\n" +
                "WHERE m.userID = ?;" ;

        PreparedStatement ps = DBUtil.getConnection().prepareStatement(sql);
        ps.setString(1,UserID);
        ResultSet rs = ps.executeQuery();
        while(rs.next()){
            Mysubmit msb = new Mysubmit();
            msb.setId(rs.getInt("id"));
            msb.setName(rs.getString("name"));
            msb.setSubmitTime(rs.getString("submitTime"));
            msb.setMaterial(rs.getString("material"));
            tmp.put(msb.getId(),msb);

//            System.out.println(msb.toString());
        }


        return tmp;
    }
}
